package demo.practice.binary_search;

public class P1064 {

    public int fixedPoint(int[] arr) {

        int min=0;
        int max=arr.length-1;

        while (min<=max){

            int mid= min+(max-min)/2;
            if(arr[mid]==mid){
                while (mid-1>=0 && arr[mid-1]==mid-1)
                    mid--;


                return mid;
            }else if(arr[mid]>mid){
                //mid值太大，寻找的值在mid的前面
                max=mid-1;
            }else{
                min=mid+1;
            }
        }

        return -1;
    }
}
